package com.briup.interfaces.impl;

import com.briup.interfaces.Backup;
import com.briup.interfaces.Configuration;

import java.io.*;
import java.util.Properties;

/**
 * 备份模块的实现类
 */
public class BackUpImpl implements Backup {
    @Override
    public Object load(String fileName, boolean del) throws Exception {
        // 根据文件名字创建文件对象
        File file = new File(fileName);
        FileInputStream fis = null;
        ObjectInputStream ois = null;

        fis = new FileInputStream(file);
        ois = new ObjectInputStream(fis);

        Object o = ois.readObject();
        // 根据del判断原文件是否删除
        if (del) {
            boolean delete = file.delete();
            // 可以根据结果判断是否被删除
        }

        return null;
    }

    @Override
    public void store(String fileName, Object obj, boolean append) throws Exception {
        File file = new File(fileName);
        FileOutputStream fos = null;
        ObjectOutputStream oos = null;

        fos = new FileOutputStream(file, append);
        oos = new ObjectOutputStream(fos);

        oos.writeObject(obj);

    }

    @Override
    public void init(Properties properties) {

    }

    @Override
    public void setConfiguration(Configuration configuration) {

    }
}
